import 'package:disk_space_plus_ohos/disk_space_plus_ohos.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  const MethodChannel channel = MethodChannel('disk_space_plus');

  setUp(() {
    channel.setMockMethodCallHandler((MethodCall methodCall) async {
      if (methodCall.method == 'getPlatformVersion') {
        return 'test_platform_version';
      } else if (methodCall.method == 'getFreeDiskSpace') {
        return 1234567890.0;
      } else if (methodCall.method == 'getTotalDiskSpace') {
        return 2000000000.0;
      } else if (methodCall.method == 'getFreeDiskSpaceForPath') {
        return 1000000000.0;
      }
      return null;
    });
  });

  tearDown(() {
    channel.setMockMethodCallHandler(null);
  });

  test('get platform version', () async {
    expect(await DiskSpacePlus.platformVersion, 'test_platform_version');
  });

  test('get free disk space', () async {
    expect(await DiskSpacePlus.getFreeDiskSpace, 1234567890.0);
  });

  test('get total disk space', () async {
    expect(await DiskSpacePlus.getTotalDiskSpace, 2000000000.0);
  });

  test('get free disk space for non-existent path', () async {
    expect(() => DiskSpacePlus.getFreeDiskSpaceForPath('/non/existent/path'),
        throwsException);
  });
}
